package com.hqyj.onlineExamination.modules.exam.controller;

import com.github.pagehelper.PageInfo;
import com.hqyj.onlineExamination.modules.common.entity.SearchBean;
import com.hqyj.onlineExamination.modules.exam.entity.Achievement;
import com.hqyj.onlineExamination.modules.exam.entity.Paper;
import com.hqyj.onlineExamination.modules.exam.service.ApprovalService;
import com.hqyj.onlineExamination.modules.common.entity.ResultEntity;
import com.hqyj.onlineExamination.modules.exam.entity.Approval;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api")
public class ApprovalController {
    @Autowired
    private ApprovalService approvalService;

    /**
     * 保存报名考试的信息。
     * 127.0.0.1/api/approval/{id}       ---- get ------
     */
    @GetMapping("/approval/{paperId}")
    public ResultEntity<Approval> insertApproval(@PathVariable Integer paperId, HttpServletRequest request){
        return approvalService.insertApproval(paperId, request);
    }


    /**
     * 学生参加考试。
     * 127.0.0.1/api/getApprovals      ---- get ------
     */
    @GetMapping("/approvals")
    public ResultEntity<Approval> getApprovals(HttpServletRequest request){
        return approvalService.getApprovals(request);
    }

    /**
     * 审批列表。
     */
    @PostMapping(value = "approvals", consumes = "application/json")
    public PageInfo<Approval> getApprovalsBySearchBean(@RequestBody SearchBean searchBean){
        return approvalService.getApprovalsBySearchBean(searchBean);
    }

    /**
     * 管理员进行审批。
     */
    @PostMapping("/approval")
    public ResultEntity<Approval> updateApprovalById(@RequestBody Approval approval){
        return approvalService.updateApprovalById(approval);
    }

    /**
     * 成绩列表。
     */
    @PostMapping(value = "/grades", consumes = "application/json")
    PageInfo<Achievement> getPapersBySearchBean(@RequestBody SearchBean searchBean, HttpServletRequest request) {
        return approvalService.getGradesBySearchBean(searchBean, request);
    }

}
